package com.csj.mvvm.algorithm

import java.util.*


object ASCIIUtil {
    /**
     * @param map    排序的键值对map
     * @param api    接口
     * @param secret 密钥
     * @return MD5加密后的str
     */
    fun getDigestByMD5(map: TreeMap<String, String>, api: String, secret: String): String {
        var sb = StringBuilder(api)
        for (entry in map.entries) {
            sb = sb.append(entry.key).append("=").append(entry.value).append("&")
        }
        sb.replace(sb.lastIndexOf("&"), sb.lastIndexOf("&") + 1, "")
        sb.append(secret)
        return MD5Util.MD5(sb.toString())
    }
}